$(function () {
    $("#div").click(function () {
        debugger;
        var css = $("#div").attr("style");
        if (css.indexOf("border: 1px solid red")>=0)
            $(this).css("border", "1px solid blue");
        else
            $(this).css("border", "1px solid red");
    });
//    $("#").click(function() {
//		alert();
//	});
    $(document).on('click', '.testItem', function(e) {
		console.log(e);
		$(e.target).toggleClass('nopass');
	});
});
var vm = new Vue({
    el : "#productTest",
    data : {
        record:{},
        sels:[],
        table: null
    },
    ready: function(){
        var _self = this;
        layui.use(['layer'], function(){
            layer = layui.layer;
        });
    },

    methods: {
        rfidLists: function(event){
            var _self = this;
            var rfid = document.getElementById("rfid").value;   //成品检验RFID
            if (event && (event.keyCode != 13 || !(rfid && rfid.length > 0))) {
                return;
            }

            var data ={
                rfid : rfid
            };
            var cpInDataByCode = [];
            _self.$nextTick(function() {
                _self.$http.post(host +"productTest/getproductTestLists",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        if(res.body.results == 'false'){
                            _self.vueAlert(res.body.msg);
                            return;
                        }
                        _self.cpInDataByCode = res.body.rfidLists;

                        cpInDataByCode =  _self.cpInDataByCode;
                        if(cpInDataByCode[0].ZYCODE != null && cpInDataByCode[0].ZYCODE !=''){
                            document.getElementById("jobCode").innerText="工单号："+cpInDataByCode[0].ZYCODE;
                        }
                        if(cpInDataByCode[0].PRODUCT != null && cpInDataByCode[0].PRODUCT !=''){
                            document.getElementById("productName").innerText="型体："+cpInDataByCode[0].PRODUCT;
                        }
                        if(cpInDataByCode[0].YSNAME != null && cpInDataByCode[0].YSNAME !=''){
                            document.getElementById("colorName").innerText="颜色："+cpInDataByCode[0].YSNAME;
                        }
                        if(cpInDataByCode[0].TIMES != null && cpInDataByCode[0].TIMES !=''){
                            document.getElementById("inTime").innerText="检验时间："+cpInDataByCode[0].TIMES;
                        }
                        if(cpInDataByCode[0].MXSTATUS != null && cpInDataByCode[0].MXSTATUS !=''){
                            document.getElementById("size").innerText="状态："+cpInDataByCode[0].MXSTATUS;
                        }

                        var ListHtml = "";
                        for( i = 0 ; i<cpInDataByCode.length ; i++){
                            if(i % 3 == 0 || i == 0){
                                ListHtml += "<div class=\"layui-row layui-col-space15\" >";
                            }
                            ListHtml += "<div class=\"layui-col-md3\" >";
                            ListHtml += "<div class=\"layui-card\" style=\"background-color: #929292;\">";
                            ListHtml += "<div class=\"layui-card-header testItem \" data-itemid='" + cpInDataByCode[i].ITEMID
                            	+ "' style=\"color : #FFFFFF; \"  >"+cpInDataByCode[i].XMNAME+"</div>";
                            ListHtml += "</div>";
                            ListHtml += "</div>";

                        }
                        $("#lastresultId").html(ListHtml);

                        layui.use(['form'], function(){
                            form = layui.form;
                            form.render(); //这个很重要
                        });

                        if(res.body.results == 'true'){
                            _self.vueAlert(res.body.msg);
                            return;
                        }


                    }
                });
            });

        },
        getChecjResult: function(event){
            var _self = this;
            var rfid = document.getElementById("rfid").value;   //成品检验RFID
            if (rfid==null || rfid.trim() =='') {
                alert("请先扫描RFID！");
                return;
            }
            var data ={
                rfid : rfid
            };
            var cpInDataByCode = [];
            _self.$nextTick(function() {
                _self.$http.post(host +"productTest/getChecjResult",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        if(res.body.results == 'false'){
                            _self.vueAlert(res.body.msg);
                            return;
                        }

                        if(res.body.results == 'true'){
                            _self.vueAlert("处理成功！！");
                            window.setTimeout(function() {
                                window.location.reload();
                            }, 1000);
                            return;

                        }


                    }
                });
            });

        },
        getNoResult: function(event){
            var _self = this;
            var rfid = document.getElementById("rfid").value;   //成品检验RFID
            if (rfid==null || rfid.trim() =='') {
                alert("请先扫描RFID！");
                return;
            }
            var data ={
                rfid : rfid
            };
            var nopassItems = [];
            $(".testItem.nopass").each(function(i, ele) {
            	nopassItems.push($(this).attr('data-itemid'));
			});
            if(nopassItems.length === 0){
            	_self.vueAlert('请先选择不合格项！');
            	return;
            }
            data.nopassItemIds = nopassItems.join(',');
            _self.$nextTick(function() {
                _self.$http.post(host +"productTest/getNoResult",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        if(res.body.results == 'false'){
                            _self.vueAlert(res.body.msg);
                            return;
                        }

                        if(res.body.results == 'true'){
                            _self.vueAlert("处理成功！！");
                            window.setTimeout(function() {
                                window.location.reload();
                            }, 1000);
                            return;

                        }


                    }
                });
            });

        },
        reset:function(data){
            window.location.reload();
        },
        vueAlert:function(msg){
            layui.use(['form'], function(){
                var layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        }
    }
});